using System;
using System.Collections;
using System.Collections.Generic;
using System.Text;

namespace ObjectModel
{
    [Serializable]
    public class Employee : ItemBase 
    {
        #region fields
        string _lastName;
        string _firstName;
        string _title;
        string _titleOfCourtesy;
        DateTime? _birthDate;
        DateTime? _hireDate;
        string _address;
        string _city;
        string _region;
        string _postalCode;
        string _country;
        string _homePhone;
        string _extension;
        byte[] _photo;
        string _notes;
        int? _reportsTo;
        string _photoPath;
        IList nativeOrders;
        OrderCollection _orders;
        bool ordersInitialised;
        #endregion

        #region ctor
        protected internal Employee() : base() { }
        #endregion

        #region properties
        public virtual string LastName
        {
            get { return _lastName; }
            set { _lastName = value; }
        }
        public virtual string FirstName
        {
            get { return _firstName; }
            set { _firstName = value; }
        }
        public virtual string Title
        {
            get { return _title; }
            set { _title = value; }
        }
        public virtual string TitleOfCourtesy
        {
            get { return _titleOfCourtesy; }
            set { _titleOfCourtesy = value; }
        }
        public virtual DateTime? BirthDate
        {
            get { return _birthDate; }
            set { _birthDate = value; }
        }
        public virtual DateTime? HireDate
        {
            get { return _hireDate; }
            set { _hireDate = value; }
        }
        public virtual string Address
        {
            get { return _address; }
            set { _address = value; }
        }
        public virtual string City
        {
            get { return _city; }
            set { _city = value; }
        }
        public virtual string Region
        {
            get { return _region; }
            set { _region = value; }
        }
        public virtual string PostalCode
        {
            get { return _postalCode; }
            set { _postalCode = value; }
        }
        public virtual string Country
        {
            get { return _country; }
            set { _country = value; }
        }
        public virtual string HomePhone
        {
            get { return _homePhone; }
            set { _homePhone = value; }
        }
        public virtual string Extension
        {
            get { return _extension; }
            set { _extension = value; }
        }
        public virtual byte[] Photo
        {
            get { return _photo; }
            set { _photo = value; }
        }
        public virtual string Notes
        {
            get { return _notes; }
            set { _notes = value; }
        }
        public virtual int? ReportsTo
        {
            get { return _reportsTo; }
            set { _reportsTo = value; }
        }
        public virtual string PhotoPath
        {
            get { return _photoPath; }
            set { _photoPath = value; }
        }
        public virtual OrderCollection Orders
        {
            get
            {
                if (!ordersInitialised)
                {
                    IList nativeCollection = orders;

                    _orders = LazyLoadCollection<OrderCollection>(typeof(Employee), this, _orders, ref nativeCollection);

                    ordersInitialised = true;

                    orders = nativeCollection;

                    if (_orders == null)
                        _orders = new OrderCollection(orders);

                }
                return _orders;
            }
        }
        #endregion

        #region protected members
        protected virtual IList orders
        {
            get
            {
                if (nativeOrders == null)
                    nativeOrders = new ArrayList();

                return nativeOrders;
            }
            set
            {
                if (value != nativeOrders)
                    nativeOrders = value;
            }
        }
        #endregion
    }
}
